package com.qianhui.listener;

import com.qianhui.common.GlobalConfig;
import weixin.popular.support.TicketManager;
import weixin.popular.support.TokenManager;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Application Lifecycle Listener implementation class TicketManagerListener
 */
public class TicketManagerListener implements ServletContextListener
{
    /**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce)
    {
        try
        {
            TokenManager.init(GlobalConfig.appID, GlobalConfig.appsecret);
            Thread.sleep(10000);
            TicketManager.init(GlobalConfig.appID);
        } catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    /**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce)
    {
        try
        {
            TokenManager.destroyed();
            TicketManager.destroyed();
        } catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
